/*
 * @FileName: app_calibration.h
 * @Author: GreyQiu qiushaogui@aikosolar.com
 * @Date: 2023-08-21 10:50:15
 * @LastEditors: GreyQiu qiushaogui@aikosolar.com
 * @LastEditTime: 2023-09-25 13:36:13
 * @Description: 
 * 
 * Copyright (c) 2023, All Rights Reserved. 
 */

#ifndef __APP_CALIBRTION_H__
#define __APP_CALIBRTION_H__

#include <stdint.h>

typedef struct
{
    uint16_t k; // 精度0.0001
    int16_t b; // 精度0.0001
} calibration_t;

typedef enum {
    FACTOR_IDX_VIN = 0,
    FACTOR_IDX_IIN,
    FACTOR_IDX_VOUT,
    FACTOR_IDX_IOUT,
    FACTOR_IDX_NUM
} FACTOR_IDX;

// 合法系数范围
#define FACTOR_K_MAX 12000 // 1.2
#define FACTOR_K_MIN 8000  // 0.8
#define FACTOR_B_MAX 30000 // 3.0
#define FACTOR_B_MIN (-30000)  // -3.0

#define FACTOR_K_DEFAULT 10000  // 0.8
#define FACTOR_B_DEFAULT 0 // 3.0

extern calibration_t factor[FACTOR_IDX_NUM];

void app_calib_init(void);
uint16_t app_calib_config(uint16_t id, uint16_t k, int16_t b);

#endif // __APP_CALIBRTION_H__
